package com.lcy.web.security

/*import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.web.authentication.www.DigestAuthenticationEntryPoint
import org.springframework.security.web.authentication.www.DigestAuthenticationFilter
import javax.sql.DataSource

*//**
 * @author loucy
 *//*

class SecurityConfig : WebSecurityConfigurerAdapter() {
    val digestEntryPoint = digestEntryPoint()
    val filter = digestFilter()

    @Autowired
    lateinit var dataSource:DataSource

    override fun configure(http: HttpSecurity) {
        http.authorizeRequests()
                .antMatchers("*")
                .hasAnyRole("user","admin")
                .and()
                .addFilter(filter)
                .httpBasic()
                .authenticationEntryPoint(digestEntryPoint)
    }

    @Autowired
    fun configureGlobal(auth: AuthenticationManagerBuilder) {
        auth.inMemoryAuthentication()
                .withUser("admin")
                .password("admin")
                .roles("admin")

        auth.jdbcAuthentication()
                .dataSource(dataSource)
                .usersByUsernameQuery("select name as username,password,id > 0 as enabled from t_user where name = ?")
                .authoritiesByUsernameQuery("select A.name as username ,C.name as role from  (select * from t_user where name = ?) as A\n" +
                        "left join  t_user_role B\n" +
                        "on B.user_id = A.id\n" +
                        "left join t_role C\n" +
                            "on C.id = B.role_id")
                .rolePrefix("ROLE_")

        filter.userDetailsService = auth.defaultUserDetailsService
    }

    final fun digestFilter():DigestAuthenticationFilter{
        val digestFilter = DigestAuthenticationFilter()
        digestFilter.setAuthenticationEntryPoint(digestEntryPoint)
        return digestFilter
    }

    final fun digestEntryPoint():DigestAuthenticationEntryPoint{
        val point = DigestAuthenticationEntryPoint()
        point.key = "web test"
        point.realmName = "Contacts Realm via Digest Authentication"
//        point.nonceValiditySeconds = 10
        return point
    }
}*/


